<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>二级库入库申请</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link th:href="@{/animate.min.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <script th:src="@{/common.js}"></script>


    <style>

        a {
            cursor: pointer;
        }


    </style>

</head>
<body style="background-color: #F8F8F8;overflow-x: hidden">
<div>


    <!--    顶部导航-->
    <div class="layui-header" style="background-color: #23262E;">
        <ul class="layui-nav layui-layout-left" style="background-color: #23262E">
            <li class="layui-nav-item"><a onclick="window.location.href='/index?account='+ getQueryVariable('account')">主页</a>
            </li>
            <li class="layui-nav-item ">
                <a href="javascript:;">一级库</a>
                <dl class="layui-nav-child">
                    <dd><a onclick="window.location.href='/addCenter?account='+ getQueryVariable('account')">入库
                    </a></dd>
                    <dd><a onclick="window.location.href='/queryCenter?account='+ getQueryVariable('account')">查询</a>
                    </dd>
                    <dd><a onclick="window.location.href='/outCenter?account='+ getQueryVariable('account')">出库申请</a>
                    </dd>
                </dl>
            </li>
            <li class="layui-nav-item layui-this">
                <a href="javascript:;">二级库</a>
                <dl class="layui-nav-child" id="nav">
                    <dd><a onclick="window.location.href='/queryAssist?account='+ getQueryVariable('account')">查询</a></dd>
                </dl>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right" style="background-color: #23262E">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <span><text th:text="${param.account}"></text></span>
                </a>
            </li>
            <li class="layui-nav-item"><a th:href="@{/userController/logout}">退出</a></li>
        </ul>
    </div>

    <div class="layui-layout layui-layout-admin">
        <div class="layui-body layui-card-body layui-card" style="background-color: #F8F8F8;position: absolute;left: 0;right: 0;top: 0;bottom:
         0;overflow-y:hidden">
            <div style="display: flex;padding: 20px;margin-top: 50px">
                <div style="width: 100%">

                    <div class="animated slideInUp" style="padding: 20px;text-align: center;margin-bottom: 10px">
                        <span style="font-size: 30px;">二级库-入库申请单</span>
                    </div>

                    <div class="animated slideInUp">
                        <form style="margin-left: 10%" class="layui-form" id="assistStoreForm">

                            <div class="layui-form-item" style="text-align: center">
                                <div>
                                    <label class="layui-form-label">流水号</label>
                                    <div class="layui-input-inline" style="width: 1000px">
                                        <input readonly style="cursor: not-allowed;" type="text" id="id"
                                               name="id"
                                               class="layui-input" lay-verify="required">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div>
                                    <label class="layui-form-label">品名</label>
                                    <div class="layui-input-inline" style="width: 1000px">
                                        <input id="name" type="text" name="name" class="layui-input"
                                               lay-verify="required">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div>
                                    <label class="layui-form-label">规格</label>
                                    <div class="layui-input-inline" style="width: 1000px">
                                        <input id="spec" type="text" name="spec" class="layui-input"
                                               lay-verify="required">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div>
                                    <label class="layui-form-label">单位</label>
                                    <div class="layui-input-inline" style="width: 1000px">
                                        <input id="unit" type="text" name="unit" class="layui-input"
                                               lay-verify="required">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div>
                                    <label class="layui-form-label">数量</label>
                                    <div class="layui-input-inline" style="width: 1000px">
                                        <input id="num" type="number" name="num" class="layui-input"
                                               lay-verify="required">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item" style="align-items: center;">
                                <div style="text-align: left;margin-left: 10%;margin-top: 50px">
                                    <button id="commit" type="button" lay-submit class="layui-btn"
                                            lay-filter="assistStoreForm"
                                            style="background-color: #23262E">
                                        申请
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>

    </div>

</div>


<script th:src="@{/layui/jquery-1.11.2.js}"></script>
<script th:src="@{/layui/layui.all.js}" charset="utf-8"></script>
<script>
    $(function () {
        layui.use(['element', 'form', 'table', 'layer'], function () {
            var element = layui.element;
            var form = layui.form;
            var table = layui.table;
            var layer = layui.layer;
            loadNav();

            if (getQueryVariable("type") == 'modify') {
                let id = getQueryVariable("id");
                $.get('/storeController/getAssist', {id: id}, function (resp) {
                    if (resp.code == 0) {
                        $("#id").val(id);
                        $("#name").val(resp.data.name);
                        $("#spec").val(resp.data.spec);
                        $("#unit").val(resp.data.unit);
                        $("#num").val(resp.data.num);
                    } else {
                        layer.msg(resp.msg);
                    }
                }, 'json');
                form.on('submit(assistStoreForm)', function (data) {
                    let formData = new FormData(data.form);
                    $.ajax({
                        url: "/storeController/modifyAssist",
                        data: formData,
                        contentType: false,
                        processData: false,
                        type: 'post', //ajax请求方式post,get
                        success: function (resp) { //请求成功后的回调函数
                            layer.msg(resp.msg);
                            setTimeout(() => run(), 1800);

                            async function run() {
                                await setTimeout;
                                window.history.go(-1);
                            }
                        }
                    });

                });
            } else {
                //生成流水号
                let current = new Date();
                let year = current.getFullYear();
                let month = current.getMonth() + 1;
                let date = current.getDate();
                let rand = parseInt(Math.random() * 10000000000);
                $("#id").val("A" + year + "" + month + "" + date + "" + rand);

                form.on('submit(assistStoreForm)', function (data) {
                    let formData = new FormData(data.form);
                    formData.append('kind',getQueryVariable("kind"));
                    formData.append('username',getQueryVariable("account"));
                    $.ajax({
                        url: "/storeController/addAssist",
                        data: formData,
                        contentType: false,
                        processData: false,
                        type: 'post', //ajax请求方式post,get
                        success: function (resp) { //请求成功后的回调函数
                            layer.msg(resp.msg);
                            setTimeout(() => run(), 1800);

                            async function run() {
                                await setTimeout;
                                window.location.reload();
                            }
                        }
                    });

                });
            }

        });
    });


</script>
</body>
</html>